package com.lzb.browser.adapter;


import android.view.View;
import android.widget.ImageView;

import androidx.annotation.NonNull;

import com.bumptech.glide.Glide;
import com.chad.library.adapter.base.provider.BaseItemProvider;
import com.chad.library.adapter.base.viewholder.BaseViewHolder;
import com.lzb.browser.R;
import com.lzb.browser.basic.ProviderMultiAdapter;
import com.lzb.browser.basic.picselect.SelectMediaEntity;
import com.lzb.browser.basic.utils.MediaUtil;
import com.lzb.browser.bean.AlbumBean;
import com.lzb.browser.utils.TimeUtil;

public class VideoAlbumAdapter extends ProviderMultiAdapter<AlbumBean> {

    private boolean isEdit;

    public VideoAlbumAdapter() {
        addItemProvider(new VideoAlbumProvider());
    }

    public void setEdit(boolean edit) {
        isEdit = edit;
        notifyDataSetChanged();
    }

    private class VideoAlbumProvider extends BaseItemProvider<AlbumBean> {
        @Override
        public int getItemViewType() {
            return ProviderMultiAdapter.TYPE_VIEW;
        }

        @Override
        public int getLayoutId() {
            return R.layout.item_sel_video;
        }

        @Override
        public void convert(@NonNull BaseViewHolder baseViewHolder, AlbumBean bean) {
            Glide.with(getContext()).load(bean.getPath())
                    .into((ImageView) baseViewHolder.getView(R.id.ivSelVideoItemImg));
            baseViewHolder.setText(R.id.tvSelVideoItemDuration, TimeUtil.getMmss(MediaUtil.getDuration(bean.getPath())));
            if (isEdit) {
                baseViewHolder.getView(R.id.ivSelVideoItemSel).setVisibility(View.VISIBLE);
                if (bean.isSelected()) {
                    baseViewHolder.setImageResource(R.id.ivSelVideoItemSel, R.drawable.xz);
                } else {
                    baseViewHolder.setImageResource(R.id.ivSelVideoItemSel, R.drawable.wxz);
                }
            } else {
                baseViewHolder.getView(R.id.ivSelVideoItemSel).setVisibility(View.GONE);
            }
        }
    }

}
